package com.guanyong.services;

import com.guanyong.dao.IUserInfoDaoMapper;
import com.guanyong.dao.IUserLoginLogDaoMapper;
import com.guanyong.model.UserInfoModel;
import com.guanyong.model.UserLoginLogModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Created by mxk on 2017/6/3.
 */
@Service
public class UserLoginLogService {
    @Autowired
    IUserLoginLogDaoMapper iUserLoginLogDaoMapper;

    @Autowired
    IUserInfoDaoMapper iUserInfoDaoMapper;

    public Integer AddLoginLog(UserLoginLogModel userLoginLogModel){
        Integer res=iUserLoginLogDaoMapper.insert(userLoginLogModel);
        if (res >-1){
            if(userLoginLogModel.getfLoginapp()!=1){
                UserInfoModel userInfoModel=new UserInfoModel();
                userInfoModel.setfId(userLoginLogModel.getfUserid());
                userInfoModel.setfLastloginapp(userLoginLogModel.getfLoginapp());
                userInfoModel.setfLastloginip(userLoginLogModel.getfLoginip());
                userInfoModel.setfLastlogintime(new Date( ));
                res =iUserInfoDaoMapper.update(userInfoModel);
            }
        }
        else{

        }
        return  1;
    }
}
